/**
 * @author kovacs peter
 *
 * This example is based on the following book:
 *
 * Title: Programmming Scala
 * Author: Dean Wampler and Alex Payne
 * Published by: O'Reilly Media, Inc.
 * ISBN: 978-0-596-15595-7
 *
 */

 package hu.kovacsp.scala.discovery.traits.ui{
    import hu.kovacsp.scala.discovery.traits.observer.Subject

    abstract class Widget

    class Button(val label: String) extends Widget {
      def click() = {
// Logic to give the appearance of clicking a button...
      }
    }

    class ObservableButton(name: String) extends Button(name) with Subject {
      override def click() = {
        super.click()
        notifyObservers
      }
    }

    class ButtonCountObserver {
      var count = 0
      def receiveUpdate(subject: Any) = count += 1
    }
  }

 package hu.kovacsp.scala.discovery.traits.observer{
    trait Subject {
      type Observer = { def receiveUpdate(subject: Any) }
      private var observers = List[Observer]()
      def addObserver(observer:Observer) = observers ::= observer
      def notifyObservers = observers foreach (_.receiveUpdate(this))
    }
  }